<template>
  <el-header>
    <div class="headerBox">
      <div class="left">
        <el-icon size="30" @click="closeSide" v-if="$store.state.isCollapsed"
          ><Expand
        /></el-icon>
        <el-icon size="30" @click="openSide" v-else><Fold /></el-icon>
        <div style="margin-left: 10px">企业门户网站管理系统</div>
      </div>
      <div class="left">
        <div style="margin-right: 10px">
          欢迎 {{ store.state.userInfo.username }} 回来
        </div>
        <el-dropdown>
          <el-icon size="20px"><User /></el-icon>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="handleCenter"
                >个人中心</el-dropdown-item
              >
              <el-dropdown-item @click="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </el-header>
</template>

<script setup>
import { useRouter } from "vue-router";
import { useStore } from "vuex";
const store = useStore();
const router = useRouter();
const closeSide = () => {
  store.commit("changeCollapsed", false);
};
const openSide = () => {
  store.commit("changeCollapsed", true);
};
const handleCenter = () => {
  router.push("/center");
};
const logout = () => {
  sessionStorage.removeItem("token");
  store.commit("clearUserInfo");
  router.push("/login");
};
</script>

<style lang="scss" scoped>
.el-header {
  background-color: #2d3a4b;
}
.headerBox {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 20px;
  color: white;
  .left {
    display: flex;
    align-items: center;
    i {
      color: white;
    }
  }
}
</style>
